package com.lpf.json.fastjson.ParseProcess;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.deserializer.ExtraProcessor;

public class TestExtraProcessor {

	public static void main(String[] args) {

		ExtraProcessor processor = new ExtraProcessor() {
			public void processExtra(Object object, String key, Object value) {

				System.out.println("---------------object = " + object);
				System.out.println("---------------key = " + key);
				System.out.println("---------------value = " + value);
				System.out.println();

				VO vo = (VO) object;
				vo.setId(789);// 修改一下id值
				vo.getAttributes().put(key, value);
			}
		};

		// 这里name和phone是多余的，在VO里没有
		VO vo = JSON.parseObject("{\"id\":123,\"name\":\"abc\",\"phone\":\"18603396954\"}", VO.class, processor);

		System.out.println("vo.getId() = " + vo.getId());
		System.out.println("vo.getAttributes().get(\"name\") = " + vo.getAttributes().get("name"));
		System.out.println("vo.getAttributes().get(\"phone\") = " + vo.getAttributes().get("phone"));
	}

}
